package chap1.version1;

public abstract class Clock {
    protected int UTC_OFFSET = 0;
    protected int localTime = 0;

    public Clock(int utcOffset) {
        UTC_OFFSET = utcOffset;
    }

    public abstract void setLocalTime(int localTime);

    public String getTime() {
        return String.valueOf(this.localTime);
    }

    public void setLocalTimeFromUtcZeroTime(int utcZeroTime) {
        localTime = Clock.makeHourWithin0To23(utcZeroTime + UTC_OFFSET);
    }

    /**
     * 把时间转化为0-23之间
     * @param hour
     * @return
     */
    private static int makeHourWithin0To23(int hour) {
        return (hour + 24) % 24;
    }
}
